'''

将所有股票的历史数据下载到本地, 共有3个参数: 

参数列表
    stock_code 股票代码, 格式为股市类型.股票编码, 如 'sh.603300'

    start_date 开始日期, 格式为 %Y-%m-%d, 如 '2024-01-01', 默认值为'2024-01-01'

    end_date 结束日期, 格式为 %Y-%m-%d, 如 '2024-12-31', 默认值为 None

    forced=False 是否强制写文件，如果保存的文件已存在，且forced为True时，会强制写入。

返回值
    无，文件会被保存在 f'./data/{stock_code}.csv', 如 ./data/600749.csv。
    
使用示例
    download_stock(stock_code, '2000-01-01')  # 下载华铁应急

【参考资料】
1. 技术文档地址: https://ai-cyber-security.feishu.cn/docx/AB1fdqV9xo9K9axwT3hcMOOcnzc
2. BaoStock官网: http://baostock.com/baostock/index.php/Python_API文档

'''
import os, sys
#import baostock as bs
#from datetime import datetime, timedelta
#import pandas as pd
#from utils.common import *
#sh.600138,中青旅,sh.600249,两面针,sh.600749,西藏旅游,sh.603707,健友股份,sz.000430,张家界	
prices = '''10.19,11.00,5.15,5.60,11.76,12.00,12.74,14.30,6.37,7.20 
9.98,11.00,5.04,5.60,11.52,12.00,12.48,14.30,6.24,7.20 
9.78,11.00,4.94,5.60,11.28,12.00,12.22,14.30,6.11,7.20 
9.57,11.00,4.83,5.60,11.04,12.00,11.96,14.30,5.98,7.20 
9.36,11.00,4.73,5.60,10.80,12.00,11.70,14.30,5.85,7.20 
9.15,11.00,4.62,5.60,10.56,12.00,11.44,14.30,5.72,7.15 
8.94,11.00,4.52,5.60,10.32,12.00,11.18,13.98,5.59,6.99 
8.74,10.92,4.41,5.51,10.08,12.00,10.92,13.65,5.46,6.83 
8.53,10.66,4.31,5.38,9.84,12.00,10.66,13.33,5.33,6.66 
8.32,10.40,4.20,5.25,9.60,12.00,10.40,13.00,5.20,6.50 
8.11,10.14,4.10,5.12,9.36,11.70,10.14,12.68,5.07,6.34 
7.90,9.88,3.99,4.99,9.12,11.40,9.88,12.35,4.94,6.18 
7.70,9.62,3.89,4.86,8.88,11.10,9.62,12.03,4.81,6.01 
7.49,9.36,3.78,4.73,8.64,10.80,9.36,11.70,4.68,5.85 
7.28,9.10,3.68,4.59,8.40,10.50,9.10,11.38,4.55,5.69 
7.07,8.84,3.57,4.46,8.16,10.20,8.84,11.05,4.42,5.53 
6.86,8.58,3.47,4.33,7.92,9.90,8.58,10.73,4.29,5.36 
6.66,8.32,3.36,4.20,7.68,9.60,8.32,10.40,4.16,5.20 
6.45,8.06,3.26,4.07,7.44,9.30,8.06,10.08,4.03,5.04 
6.24,7.80,3.15,3.94,7.20,9.00,7.80,9.75,3.90,4.88'''

data = []
for str in prices.split('\n'):
    d0 = []
    for sv in str.split(','):
        d0.append(float(sv))
    data.append(d0)

vs = [ [], [], [], [], [] ]
vso = [ [], [], [], [], [] ]
for ds in data:
    vs[0].append(ds[0])
    vs[1].append(ds[2])
    vs[2].append(ds[4])
    vs[3].append(ds[6])
    vs[4].append(ds[8])
    vso[0].append(ds[+1])
    vso[1].append(ds[+1])
    vso[2].append(ds[+1])
    vso[3].append(ds[+1])
    vso[4].append(ds[+1])

#print(vs)
names_ch = ['中 青 旅','两 面 针','西藏旅游','健友股份','张 家 界',]
names_en = ['zql','lmz','xzly','jygf','zjj',]
dicts = {
    'zql':vs[0],
    'lmz':vs[1],
    'xzly':vs[2],
    'jygf':vs[3],
    'zjj':vs[4]
}

name = 'zjj'
level = 1

if len(sys.argv) > 1:
    name = sys.argv[1]

if name == 'all':
    pos = [int(v) for v in sys.argv[2]]
    for i in range(len(names_ch)):
        name = names_ch[i]
        key = names_en[i]
        level = pos[i]
        in_price = data[level-1][i*2]
        out_price = data[level-1][i*2+1]
        print(f'{name}: {in_price:6.2f} -> {out_price:6.2f}') 


        #print(f'{names_ch[i]}: {dicts[names_en[i]][pos[i]-1]:6.2f} -> ') 
    sys.exit(0)


if len(sys.argv) > 2:
    level = int(sys.argv[2])



print(dicts[name][level])